<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-05-06 00:05:39
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Models;

use App\Traits\SoftDeletesTrait;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Storage;

class Attachment extends BaseModel
{
    use SoftDeletesTrait;
    public $timestamps = true;
    public $table = "sys_attachment";
    protected $guarded = [];
    protected $appends = ['url', 'thumb_url'];
    public function getSourceAttribute()
    {
        return isEmpty($this->source_model) ? null :
            App::make($this->source_model)->where($this->source_key, "=", $this->source_value)->first();
    }
    public function getUrlAttribute()
    {
        return Storage::url($this->filepath);
    }
    public function getThumbUrlAttribute()
    {
        return Storage::url($this->filethumbnail);
    }
}
